package com.china08.yxyapi.repository.mg.scoreport;

import java.util.Date;
import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import com.china08.yxyapi.entity.mg.scoreport.Exam;
import com.china08.yxyapi.entity.mg.scoreport.ExamStudent;

public interface ExamStudentRepository extends MongoRepository<ExamStudent, String> {

    /*
     * 根据考试查询全部考试成绩
     */
    List<ExamStudent> findByExam(Exam exam);

    List<ExamStudent> findByExamOrderByStuTotalScoreDesc(Exam exam);

    /**
     * 根据考试实体类和总分数查询记录
     * 
     * @param exam
     * @param stuTotalScore
     * @return
     */
    Long countByExamAndStuTotalScore(Exam exam, Double stuTotalScore);

    /**
     * 根据考试实体类和不包含总分数查询记录
     * 
     * @param exam
     * @param stuTotalScore
     * @return
     */
    Long countByExamAndStuTotalScoreNot(Exam exam, double stuTotalScore);

    /**
     * 根据考试实体类,对学生成绩进行由高到低排序,并且获取第一名
     * 
     * @param exam
     * @return
     */
    ExamStudent findTopByExamOrderByStuTotalScoreDesc(Exam exam);

    /**
     * 根据考试实体类
     * 
     * @param stuTotalScore
     * @return
     */
    List<ExamStudent> findByExamAndStuTotalScore(Exam exam, Double stuTotalScore);

    /**
     * 根据考试实体类,对学生成绩进行由低到高排序,并且获取最后第一名
     * 
     * @param exam
     * @return
     */
    ExamStudent findTopByExamOrderByStuTotalScoreAsc(Exam exam);

    /**
     * 根据考试实体类,对学生成绩进行由低到高排序并且也按录入时间排序,并且获取最后第一名
     * 
     * @param exam
     * @return
     */
    ExamStudent findTopByExamOrderByStuTotalScoreAscCreatedDateAsc(Exam exam);

    List<ExamStudent> findByExamOrderByStuTotalScoreDescCreatedDateAsc(Exam exam);

    ExamStudent findTopByExamOrderByStuTotalScoreDescCreatedDateAsc(Exam exam);

    List<ExamStudent> findTop3ByExamOrderByStuTotalScoreAscCreatedDateAsc(Exam exam);

    Long countByExamAndStuTotalScoreGreaterThan(Exam exam, Integer youxiu);

    Long countByExamAndStuTotalScoreLessThan(Exam exam, Integer bujigeguocha);

    List<ExamStudent> findByExamAndStuTotalScoreLessThan(Exam examLast, Integer bujige1);

    @Query(value = "{'exam.id' : ?0 ,'student_id' : ?1 }")
    ExamStudent findByExamAndStudentId(String examId, String studentId);

    Long countByExamAndStuTotalScoreBetween(Exam exam, Integer lianghao, Integer youxiu1);

    List<ExamStudent> findByExamAndStuTotalScoreNot(Exam exam, double d);

    List<ExamStudent> findByExamIn(List<Exam> exam);

    List<ExamStudent> findByStudentIdAndIdNotAndCreatedDateGreaterThanEqual(String studentId, String id, Date date);

    ExamStudent findTop1ByStudentIdAndExamNotOrderByCreatedDateDesc(String studentId, String examid);

    Long countByExamAndStuTotalScoreGreaterThanEqual(Exam exam, Integer youxiu1);

    Long countByExamAndStuTotalScoreBetween(Exam examLast, Integer lianghao2, double d);

    Long countByExamAndStuTotalScoreBetween(Exam exam, double d, double d2);

    Long countByExamAndStuTotalScoreLessThanEqual(Exam examLast, Integer youxiu2);

}
